<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="back iconfont icon-xiangzuo1" @tap="backPage"></view>
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">个人资料</view>
		</view>	
		<view class="bg_box">
			<image class="bg01" :src="getImgSrc('/static/bg02.png')" mode="widthFix"></image>
			<view class="bg_content">
				
				<view class="avatar_box" @click="up_img">
					<image class="a01" :src="avatar" mode="scaleToFill"></image>
					<image class="a02" :src="getImgSrc('/static/addimg01.png')" mode="widthFix"></image>
				</view>
					
				<view class="details_box">
					<view class="list">
						<view class="name">用户昵称</view>
						<input type="text" v-model="nickname" value="" placeholder="请输入用户昵称" />
					</view>
					<!-- <view class="list">
						<view class="name">手机号</view>
						<input type="text" v-model="phone" value="" placeholder="请输入手机号" />
					</view> -->
					<view class="list">
						<view class="name">邮箱</view>
						<input type="text" v-model="email" value="" placeholder="请输入邮箱" />
					</view>
					
				</view>
				<view class="clear_box04"></view>
				
				<view class="confirm" @click="commit()">确认</view>
				
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				scrrol:false,
				info:'',
				avatar:'',
				// phone:'',
				nickname:'',
				email:'',
			}
		},
		onLoad() {
			let that = this;
			that.loadData();
		},
		methods: {
			loadData() {
				let that = this;
				that.Net._get('auth/info', {}, res => {
					if (res.code == 200) {
						that.info = res.data;
						that.avatar = res.data.avatar;
						// that.phone = res.data.phone;
						that.nickname = res.data.nickname;
						if (res.data.email){
							that.email = res.data.email;
						}
					}
				});
			},
			commit() {
				let that = this;
				let param = {
					avatar:that.avatar,
					phone:that.phone,
					nickname:that.nickname,
					email:that.email,
				};
				that.Net._post('auth/edit_info', param, res => {
					if (res.code == 200) {
						that.Msg.Success('修改成功', res => {
							that.loadData();
						});
					}
				});
			},
			up_img(e) {
				let that = this;
				uni.chooseImage({
					sizeType: ['original', 'compressed'], // 可选择原图或压缩后的图片
					sourceType: ['album', 'camera'], // 可选择性开放访问相册、相机
					success: function (res) {
						const temFilePath = res.tempFilePaths; // 图片选择完成后 获取该图片的路劲
						uni.uploadFile({
							url:that.Cfg.Setting.root + 'app/upload_image', // 上传文件的Controller
							filePath: temFilePath[0], // 要上传的文件路径
							name:'file',
							success: (res) => {
								console.log(JSON.parse(res.data))
								let imgData = JSON.parse(res.data)
								that.avatar = imgData.data;
							}
						})
					}
				});
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},

		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
		onReachBottom() {
		  var that = this;
		  that.page++;
		  // that.Net._get('shop_goods', {per_page:'10',page:that.page,}, res => {
		  //   if (res.code == 200) {
		  //     //console.log(res)
		  //     if (res.data.data == '') {
		  //       uni.showToast({
		  //         title: '已经是最后一页了',
		  //         duration: 2000,
		  //         icon: 'none'
		  //       });
		  //     } else {
		  //       that.info = that.info.concat(res.data.data); //将数据拼接在一起
		  //     }
		  //   } else if (res.code == 0) {
		  //     that.Msg.Success(res.msg, res => {});
		  //   }
		  // });
		},
	}
</script>

<style>
	
	.header{
		background-color: transparent !important;
	}
	
	.header .text{
		background-color: transparent !important;
		color: #333 !important;
	}
	
	.header .back{
		color: #333 !important;
	}
	
	.scrrolHeader{
		background-color: #FFE6D0 !important;
	}
	
	.bg_box{
		width: 100%;
		position: relative;
	}
	
	.bg_box .bg01{
		width: 100%;
	}
	
	.bg_box .bg_content{
		width: 92%;
		position: absolute;
		left: calc(50% - 46%);
		top: calc(13.5vw + var(--status-bar-height));
		z-index: 98;
	}
	
	.details_box {
		width: 100%;
		margin-top: 4%;
		background-color: #fff;
		padding: 5vw 4%;
		border-radius: 3vw;
	}
	
	.details_boxNo{
		padding: 0vw 4%;
	}
	
	.details_box .details_title {
		font-size: 4.2vw;
		color: #333;
		font-weight: bold;
		margin-bottom: 5vw;
	}
	
	.details_box .input_box{
		width: 100%;
		display: flex;
		align-items: center;
		border-bottom: 2px solid #FC5D20;
		height: 15vw;
	}
	
	.details_box .input_box .m{
		font-size: 4vw;
		color: #333;
		margin-right: 1vw;
		font-weight: bold;
		margin-top: 2vw;
	}
	
	.details_box .input_box input{
		font-size: 7vw;
		color: #333;
		flex: 1;
		font-weight: bold;
	}
	
	.details_box .list {
		width: 100%;
		padding: 5vw 0;
		border-bottom: 1px solid #F3F3F3;
		display: flex;
		align-items: center;
		position: relative;
	}
	
	.details_box .list .name {
		font-size: 4.2vw;
		font-weight: bold;
		color: #333;
		margin-right: 4vw;
	}
	
	.details_box .list .text {
		flex: 1;
		font-size: 3.5vw;
		color: #333;
		margin-right: 1vw;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}
	
	.details_box .list .text .i{
		width: 5vw;
		margin-right: 1vw;
	}
	
	.details_box .list .text .i image{
		width: 100%;
	}
	
	.details_box .list input {
		flex: 1;
		font-size: 3.5vw;
		color: #333;
		margin-right: 3vw;
		text-align: right;
		font-weight: bold;
	}
	
	.details_box .list .arrow {
		font-size: 3.5vw;
		color: #333;
	}
	
	.details_box .list .yzm {
		font-size: 3.5vw;
		color: #FC5D20;
		font-weight: bold;
		outline: none;
		background-color: transparent !important;
		border-radius: 10vw;
		height: 10vw;
		border: 1px solid #FC5D20;
	}
	
	.standing{
		width: 100%;
	}
	
	.standing image{
		width: 100%;
	}
	
	.standing .text{
		width: 100%;
		font-size: 3.8vw;
		color: #333;
		font-weight: bold;
		margin-top: 3vw;
		text-align: center;
	}
	
	.details_box .standing:nth-child(2){
		margin-top: 5vw;
	}
	
	.avatar_box{
		width: 30vw;
		height: 30vw;
		border-radius: 50%;
		margin: 10vw auto;
		position: relative;
		background-color: #fff;
		padding: 1vw;
	}
	
	.avatar_box .a01{
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}
	
	.avatar_box .a02{
		width: 8vw;
		position: absolute;
		right: 0;
		bottom: 0;
	}
	
	
	
	
</style>
